package com.woniuxy.Mapper;

import com.woniuxy.entity.Department;
import com.woniuxy.entity.Doctor;
import com.woniuxy.vo.schedulesDoc;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface departmentMapper {

    @Select("select departments.* from departments")
    @Results({
            @Result(column = "department_id", property = "departmentId"),
    })
    List<Department> findAll();

    // 根据科室id 获取 医生的信息
    @Select("SELECT doc.* FROM doctors doc JOIN departments dept ON doc.department_id = dept.department_id WHERE dept.department_id = #{departmentId} ")
    @Results({
            @Result(column = "department_id", property = "departmentId"),
            @Result(column = "doctor_id", property = "doctorId"),
            @Result(column = "is_active", property = "isActive"),
    })
    List<Doctor> getDoctorsByDepartID(Integer departmentId);

    @Select("SELECT  doc.name AS 'dname', s.*, (s.max_appointments - s.current_appointments) AS 'DeleteNumber' FROM schedules s JOIN doctors doc ON s.doctor_id = doc.doctor_id WHERE doc.doctor_id = #{doctorId} AND s.date >= CURDATE()  ORDER BY s.date, s.time_slot; ")
    @Results({
            @Result(column = "dname", property = "dname"),
            @Result(column = "DeleteNumber", property = "DeleteNumber"),
            @Result(column = "current_appointments", property = "currentAppointments"),
            @Result(column = "delete_number", property = "deleteNumber"),
            @Result(column = "doctor_id", property = "doctorId"),
            @Result(column = "max_appointments", property = "maxAppointments"),
            @Result(column = "registration_fee", property = "registrationFee"),
            @Result(column = "schedule_id", property = "scheduleId"),
            @Result(column = "time_slot", property = "timeSlot"),
    })
    List<schedulesDoc> getSchedules(Integer doctorId);
}
